package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.base.Page;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.SkuManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product")
public class SkuManageController {

    @Autowired
    private SkuManageService skuManageService;

    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        skuManageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }

    //admin/product/list/1/10?category3Id=61
    @GetMapping("/list/{page}/{size}")
    public Result pageList(@PathVariable Long page,
                           @PathVariable Long size,
                           @RequestParam Long category3Id){
        Page<SkuInfo> skuInfoPage = skuManageService.pageList(page,size,category3Id);

        return Result.ok(skuInfoPage);
    }

    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        skuManageService.onSale(skuId);
        return Result.ok();
    }


    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){
        skuManageService.cancelSale(skuId);
        return Result.ok();
    }


}
